
*** Set Fixed Effects and Clustering
global fe "courtq"
global clusvar "partyr"

************************************
***** Reduced form Placebos *******
************************************

capture frame drop rfplacebo 
frame create rfplacebo  str55 outcome str32 specification beta se N 

replace samp=(sentDOL==1)
** Labor 
** -1, -8
reghdfe ly1t2earn stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("EARNQ-1-8") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum ly1t2earn if e(sample)==1 & evictionorder!=1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("EARNQ-1-8") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

** -9, -12
reghdfe ly2t3earn stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("EARNQ-9-12") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum ly2t3earn if e(sample)==1 & evictionorder!=1
frame post rfplacebo ("EARNQ-9-12") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

replace samp=all
** Homeless
** -1 
reghdfe lshelt1yr stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("ESHUY-1") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum lshelt1yr if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("ESHUY-1") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

** -1 
reghdfe lhomelessapp1yr stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("HOMEY-1") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum lhomelessapp1yr if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("HOMEY-1") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

** Move
** -1,-2 
reghdfe l0t1add stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("MOVEY-1-2") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum l0t1add  if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("MOVEY-1-2") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

** Neigh Pov
** -1 
reghdfe l0t1pov stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("POVY-1-2") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum l0t1pov  if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("POVY-1-2") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 


** Demographic

reghdfe female stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("FEMALE") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum female if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("POVY-1-2") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

reghdfe black stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("BLACK") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum black if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("BLACK") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

reghdfe hisp stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("HISP") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum hisp if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("HISP") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

reghdfe owedamount stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("RENTOWED") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum owedamount  if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("RENTOWED") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

reghdfe nopriorcase stringency if samp==1, absorb($fe) cluster($clusvar)
frame post rfplacebo ("NOPRIOR") ("RF") (_b[stringency]) (_se[stringency]) (e(N)) 
sum nopriorcase if e(sample)==1 & evictionorder!=1
frame post rfplacebo  ("NOPRIOR") ("MEANSD") (r(mean)) (r(sd)) (r(N)) 

frame rfplacebo : saveold "${Inputs}/NY_rf_placebo.dta", replace



************************************
***** Fist Stage by Sub-Samp *******
************************************
/* 
With and without controls
F-stat (Full), Partial 
*/
global exactcontrols "black hisp female blackfemale hispfemale  ageatfiling age2 age3 sh_hhpov med_grossrent logclaim logclaim2 multicase"
global controls $exactcontrols

*** Using ivreghdfe to get correct First Stage F-statistic
*** am using a random number as the "outcome" in the second stage
set seed 10202016
gen numberrandom=rnormal()


capture frame drop fssubsamp
frame create fssubsamp beta se fstat str50 specification str35 group N

foreach c in female black multicase { 

	ivreghdfe numberrandom (evictionorder = zevictionorder) if samp==1 & `c'==1, absorb($fe) cluster($clusvar) ffirst
	local F `=e(widstat)'	
	ivreghdfe evictionorder stringency  if nonpay==1 & `c'==1 & sentDOL==1, absorb(courtqdow zipfe) cluster(yrpartclass)
	frame post fssubsamp (_b[stringency]) (_se[stringency]) (`F') ("First Stage, No Controls") ("`c'") (e(N))

	ivreghdfe numberrandom $controls (evictionorder = stringency) if samp==1 & `c'==1, absorb($fe) cluster($clusvar)  ffirst
	local F `=e(widstat)'	
	ivreghdfe evictionorder stringency $controls  if samp==1 & `c'==1, absorb($fe) cluster($clusvar) 
	frame post fssubsamp (_b[stringency]) (_se[stringency]) (`F') ("First Stage, With Controls") ("`c'") (e(N))

	

	ivreghdfe numberrandom (evictionorder = stringency) if samp==1 & `c'==1, absorb($fe) cluster($clusvar)  ffirst
	local F `=e(widstat)'	
	ivreghdfe evictionorder stringency  if samp==1 & `c'==1, absorb($fe) cluster($clusvar) 
	frame post fssubsamp (_b[stringency]) (_se[stringency]) (`F') ("First Stage, No Controls") ("Not`c'") (e(N))

	ivreghdfe numberrandom $controls (evictionorder = stringency) if samp==1 & `c'==1, absorb($fe) cluster($clusvar)  ffirst
	local F `=e(widstat)'	
	ivreghdfe evictionorder stringency $controls  if samp==1 & `c'==1, absorb($fe) cluster($clusvar) 
	frame post fssubsamp (_b[stringency]) (_se[stringency]) (`F') ("First Stage, With Controls") ("Not`c'") (e(N))

	
	}

ivreghdfe numberrandom (evictionorder = stringency) if samp==1, absorb($fe) cluster($clusvar)  ffirst
local F `=e(widstat)'	
ivreghdfe evictionorder stringency  if samp==1, absorb($fe) cluster($clusvar) 
frame post fssubsamp (_b[stringency]) (_se[stringency]) (`F') ("First Stage, No Controls") ("All") (e(N))

ivreghdfe numberrandom $controls (evictionorder = stringency) if samp==1, absorb($fe) cluster($clusvar) ffirst
local F `=e(widstat)'	
ivreghdfe evictionorder stringency $controls  if samp==1, absorb($fe) cluster($clusvar) 
frame post fssubsamp (_b[stringency]) (_se[stringency]) (`F') ("First Stage, With Controls") ("All") (e(N))
	
frame change fssubsamp
replace group = upper(group)
replace group = "FIRSTCASE" if group=="NOTMULTICASE" 
replace group = "NOTFIRSTCASE" if group=="MULTICASE" 

frame fssubsamp: saveold "${Inputs}\NY_fs_subgroups.dta", replace
frame change default
